import 'package:flutter/material.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:get/get.dart';
import 'package:star_author/config/base_configuration.dart';
import 'package:star_author/widgets/cover_widget.dart';

//todo:主播信息---用户
class AnchorInfo extends StatefulWidget {
  const AnchorInfo({Key? key}) : super(key: key);

  @override
  _AnchorInfoState createState() => _AnchorInfoState();
}

class _AnchorInfoState extends State<AnchorInfo> {
  @override
  Widget build(BuildContext context) {
    return Container(
      decoration: BoxDecoration(
        color: Colors.white,
        borderRadius: BorderRadius.circular(16),
      ),
      width: Get.width,
      padding: EdgeInsets.symmetric(horizontal: 12, vertical: 20),
      constraints: BoxConstraints(
        maxHeight: Get.height * 0.5,
      ),
      child: ListView(
        shrinkWrap: true,
        children: [
          Row(
            children: [
              buildCircleCover(
                size: 40,
              ),
              SizedBox(
                width: 8,
              ),
              Container(
                height: 40,
                child: Column(
                  mainAxisAlignment: MainAxisAlignment.spaceBetween,
                  crossAxisAlignment: CrossAxisAlignment.start,
                  children: [
                    Text(
                      "翡翠01号直播间",
                      style: TextStyle(
                        fontSize: 14,
                        color: ColorConf.normal,
                        fontWeight: FontWeight.w500,
                      ),
                    ),
                    Text(
                      "翡翠01号直播间",
                      style: TextStyle(
                        fontSize: 12,
                        color: ColorConf.lightGray,
                      ),
                    ),
                  ],
                ),
              ),
            ],
          ),
          Container(
            margin: EdgeInsets.only(top: 20),
            child: Container(
              child: GridView.builder(
                physics: NeverScrollableScrollPhysics(),
                gridDelegate: SliverGridDelegateWithFixedCrossAxisCount(
                    crossAxisCount: 2,
                    mainAxisSpacing: 15.0,
                    crossAxisSpacing: 10.0,
                    childAspectRatio: 5),
                itemBuilder: (context, index) {
                  bool isLiving = index.isOdd;
                  Color color_bg;
                  Color color_text_bg;
                  String text = "";
                  if (isLiving) {
                    color_bg = Color(0xFFFFFAED);
                    color_text_bg = Color(0xFFFEBA07);
                    text = "直播中";
                  } else {
                    color_bg = Color(0xFFF6F6F6);
                    color_text_bg = Color(0xFFCCCCCC);
                    text = "休息中";
                  }
                  return Container(
                    width: (Get.width - 24 - 20) / 2,
                    padding: EdgeInsets.symmetric(
                      horizontal: 18,
                    ),
                    child: Row(
                      children: [
                        buildCircleCover(
                          size: 24,
                        ),
                        const SizedBox(
                          width: 8,
                        ),
                        Expanded(
                          child: Text(
                            "主播姗姗主播姗姗主播姗姗主播姗姗主播姗姗",
                            style: TextStyle(
                              fontSize: 14,
                              color: ColorConf.normal,
                            ),
                            maxLines: 1,
                            overflow: TextOverflow.ellipsis,
                          ),
                        ),
                        Container(
                          decoration: BoxDecoration(
                            color: color_text_bg,
                            borderRadius: BorderRadius.circular(2),
                          ),
                          margin: EdgeInsets.only(
                            left: 6,
                          ),
                          padding:
                              EdgeInsets.symmetric(horizontal: 2, vertical: 1),
                          child: Text(
                            text,
                            style: TextStyle(
                              fontSize: 8,
                              height: 1.2,
                              color: Colors.white,
                            ),
                          ),
                        )
                      ],
                    ),
                    decoration: BoxDecoration(
                      color: color_bg,
                      borderRadius: BorderRadius.circular(8),
                    ),
                  );
                },
                shrinkWrap: true,
                itemCount: 5,
                scrollDirection: Axis.vertical,
              ),
            ),
          ),
          Container(
            height: 20,
          )
        ],
      ),
    );
  }
}

//todo:下线 or 删除发言
class AnchorOffline extends StatefulWidget {
  Function? sure;

  AnchorOffline({Key? key, this.sure}) : super(key: key);

  @override
  _AnchorOfflineState createState() => _AnchorOfflineState();
}

class _AnchorOfflineState extends State<AnchorOffline> {
  @override
  Widget build(BuildContext context) {
    return Container(
      padding: EdgeInsets.only(
        top: 24.w,
      ),
      child: Column(
        children: [
          Container(
            alignment: Alignment.center,
            padding: EdgeInsets.only(
              left: 12.w,
              right: 12.w,
            ),
            child: Text(
              "关闭直播间后，观众将被强制退出当前直播间，确定关闭吗？",
              style: TextStyle(
                fontSize: 16.sp,
                color: ColorConf.normal,
              ),
              textAlign: TextAlign.center,
            ),
          ),
          SizedBox(
            height: 24.w,
          ),
          Container(
            height: 43.w,
            decoration: BoxDecoration(
              border: Border(
                top: BorderSide(
                  color: Color(0xFFEEEEEE),
                  width: 1.w,
                ),
              ),
            ),
            child: Row(
              children: [
                Expanded(
                  child: InkWell(
                    onTap: () {
                      Get.back();
                    },
                    child: Text(
                      "取消",
                      style:
                          TextStyle(fontSize: 16.sp, color: Color(0xFF666666)),
                      textAlign: TextAlign.center,
                    ),
                  ),
                ),
                Container(
                  height: 43.w,
                  width: 1.w,
                  color: Color(0xFFEEEEEE),
                ),
                Expanded(
                    child: InkWell(
                  onTap: () {
                    Get.back();
                    widget.sure!();
                  },
                  child: Text(
                    "确定关闭"
                    "",
                    style: TextStyle(
                        fontSize: 16.sp,
                        color: Color(0xFFE02020),
                        fontWeight: FontWeight.w500),
                    textAlign: TextAlign.center,
                  ),
                ))
              ],
            ),
          )
        ],
      ),
    );
  }
}
